/*
 * Copyright 2006-2023 ahtelit.com, All Rights Reserved.
 */

package com.telit.android.dto.easyexcel;

import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.annotation.ExcelProperty;
import com.alibaba.excel.annotation.format.DateTimeFormat;
import com.alibaba.excel.annotation.write.style.ColumnWidth;
import com.alibaba.excel.annotation.write.style.HeadStyle;
import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.poi.BorderStyleEnum;
import com.alibaba.excel.enums.poi.FillPatternTypeEnum;
import com.alibaba.excel.metadata.data.WriteCellData;
import lombok.*;

import java.util.Date;


/**
 * 导出火情列表DTO
 *
 * @author yuezhuang
 * @since 2023-03-10
 */
@HeadStyle(fillPatternType = FillPatternTypeEnum.SOLID_FOREGROUND, fillForegroundColor = 22,
        borderLeft = BorderStyleEnum.THIN, borderRight = BorderStyleEnum.THIN, borderTop = BorderStyleEnum.THIN, borderBottom = BorderStyleEnum.THIN)
@EqualsAndHashCode(callSuper = false)
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CommFireAlarmsExcelDTO extends BasicExcelDTO {

    public static class FireStatusConverter implements Converter<String> {

        @Override
        public WriteCellData<?> convertToExcelData(WriteConverterContext<String> context) throws Exception {
            String status = context.getValue();
            String statueName = "待接警";
            if (StrUtil.isNotEmpty(status)) {
                switch (status) {
                    case "1":
                        statueName = "待接警";
                        break;
                    case "2":
                        statueName = "待核实";
                        break;
                    case "3":
                        statueName = "待处置";
                        break;
                    case "4":
                        statueName = "处置中";
                        break;
                    case "5":
                        statueName = "已处置";
                        break;
                    case "6":
                        statueName = "误报";
                        break;
                    default:
                        context.setValue("误报");
                }
            }
            return new WriteCellData<>(statueName);
        }

    }


    public static class FireResourceConverter implements Converter<String> {

        @Override
        public WriteCellData<?> convertToExcelData(WriteConverterContext<String> context) throws Exception {
            String resource = context.getValue();
            String resourceName = "护林员";
            if (StrUtil.isNotEmpty(resource)) {
                switch (resource) {
                    case "1":
                        resourceName = "护林员";
                        break;
                    case "2":
                        resourceName = "飞手";
                        break;
                    case "3":
                        resourceName = "视频监控";
                        break;
                    case "4":
                        resourceName = "卫星";
                        break;
                    case "5":
                        resourceName = "无人机";
                        break;
                    case "6":
                        resourceName = "电话接警";
                        break;
                    case "7":
                        resourceName = "防火管理员";
                        break;
                    case "8":
                        resourceName = "视频监控";
                        break;
                    default:
                        context.setValue("视频监控");
                }
            }
            return new WriteCellData<>(resourceName);
        }

    }


    @ColumnWidth(10)
    @ExcelProperty(value = "序号", index = 0)
    private Integer num;

    @ExcelProperty(value = "火情状态", index = 1, converter = FireStatusConverter.class)
    private String status;

    @DateTimeFormat("yyyy-MM-dd HH:mm:ss")
    @ExcelProperty(value = "报警时间", index = 2)
    private Date findTime;

    @ExcelProperty(value = "所属行政区划", index = 3)
    private String districtName;

    @ExcelProperty(value = "地址", index = 4)
    private String detailAddress;

    @ExcelProperty(value = "经纬度", index = 5)
    private String longitudeAndLatitude;

    @ExcelProperty(value = "报警源类型", index = 6, converter = FireResourceConverter.class)
    private String source;

    @ExcelProperty(value = "报警源名称", index = 7)
    private String sourceName;

    @ExcelProperty(value = "火情描述", index = 8)
    private String content;

}
